version 14.0

log using "\Users\sgolder\Dropbox\Portfolio Allocation\replication\figure5.log", replace
set more off
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      africancabinets_figure5.do                      *;
*       Date:           September 19, 2016                              *;
*       Author:         Molly Ariotti and Sona Golder                   *;
*       Purpose:      	Produce Figure 5 in appendix for CPS African    *;
*                       portfolio allocation paper.                     *;
* 	    Input File:     africa.dta, europe.dta                          *;
*       Output File:    figure5.log, nonformateur.eps                   *;
*                       formateur.eps                                   *;
*       Data Output:    none                                            *;             
*       Previous file:  none                                            *;
*       Machine:        laptop                           				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

use "\Users\sgolder\Dropbox\Portfolio Allocation\replication\Africa.dta"; 

sum;

desc;

*     ****************************************************************  *;
*       Drop African cabinets where there is no formateur coded.        *;
*       (One in Guinea-Bissau, one in Sao Tome & Principe               *;
*     ****************************************************************  *;

drop if cabinetcode == 5;
drop if cabinetcode == 23;

*     ****************************************************************  *;
*       Add Europe data from Warwick and Druckman (2006)                *;
*     ****************************************************************  *;

append using "\Users\sgolder\Dropbox\Portfolio Allocation\replication\Europe.dta"; 

*     ****************************************************************  *;
*       Drop European cabinets where there is no formateur coded.       *;
*      (These are caseno 531, 532, 533, 534, 542,543, 617, 858, 859)    *;
*     ****************************************************************  *;

drop if code == 205097;
drop if code == 205098;
drop if code == 205099;
drop if code == 205100;
drop if code == 205108;
drop if code == 205109;
drop if code == 207130;
drop if code == 209184;
drop if code == 209185;

*     ****************************************************************  *;
*       Create regional dummy variables                                 *;
*     ****************************************************************  *;

gen africa = . ;
replace africa = 1 if region==1;
replace africa = 0 if region==2;
replace africa = 0 if region==3;

gen europe = . ;
replace europe = 0 if region==1;
replace europe = 1 if region==2;
replace europe = 0 if region==3;

gen america = . ;
replace america = 0 if region==1;
replace america = 0 if region==2;
replace america = 1 if region==3;

*     ****************************************************************  *;
*       Create interaction terms for analysis in Table 1                *;
*     ****************************************************************  *;

gen seatshare_africa=africa*seatshare;
gen formateur_africa=africa*formateur;


*     ****************************************************************  *;
*       Observed range of Seatshare for non-formateur parties.          *;
*     ****************************************************************  *;

sum seatshare if formateur==0;

*     ****************************************************************  *;
*       Observed range of Seatshare for formateur parties.              *;
*     ****************************************************************  *;

sum seatshare if formateur==1;

*     ****************************************************************  *;
*       Table 1, Model 4 combined                                       *;
*     ****************************************************************  *;

regress portfolioshare seatshare formateur africa seatshare_africa formateur_africa, robust;

*     ****************************************************************  *;
*       Collect the pieces necessary for Figure 4 (in the appendix)     *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);

scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];

scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];

scalar covb3b4=V[3,4];
scalar covb3b5=V[3,5];

scalar list b3 b4 b5 varb3 varb4 varb5 covb3b4 covb3b5;

*     ****************************************************************  *;
*       Create values for horizontal axis                               *;
*     ****************************************************************  *;

set obs 1000;

gen MVZ = (_n-1)/1000;

*     ****************************************************************  *;
*       Create information for non-formateur parties                    *;
*     ****************************************************************  *;

gen marginal_nonformateur = b3+b4*MVZ;

gen se_nonformateur = sqrt(varb3+varb4*(MVZ^2)+2*MVZ*covb3b4);

gen bound = 1.96*se_nonformateur;

gen upper = marginal_nonformateur+bound;

gen lower = marginal_nonformateur-bound;

gen yline=0;

*     ****************************************************************  *;
*       Produce Figure 5 (appendix), Panel a: Non-formateur parties     *;
*     ****************************************************************  *;

graph twoway hist seatshare if formateur==0 & seatshare<0.74, width(0.04) percent color(gs15) yaxis(2)
    || line marginal_nonformateur MVZ if MVZ<0.74 & MVZ>0.002, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower MVZ if MVZ<0.74 & MVZ>0.002, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper MVZ if MVZ<0.74 & MVZ>0.002, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel(-0.15 -0.12 -0.09 -0.06 -0.03 0 0.03, axis(1) nogrid labsize(2.5))
    ylabel(0 3 6 9 12 15 18, axis(2) nogrid labsize(2.5) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(a) Non-Formateur Parties}",  size(3.5))
        xtitle("{stSerif:Share of Government's Legislative Seats}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Africa}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)); 

      
graph export "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\nonformateur.eps", replace;

*     ****************************************************************  *;
*       Calculating percentage of observations that fall in region of   *;
*       significance 565/568 = 99%                                      *;
*     ****************************************************************  *;

list countryname cabinetcode year seatshare if seatshare>0.667 & formateur==0;

sum cabinetcode if formateur==0;

*     ****************************************************************  *;
*       Create information for formateur parties                        *;
*     ****************************************************************  *;      
        
gen marginal_formateur = b3+b4*MVZ + b5;

gen se_formateur = sqrt(varb3+varb4*(MVZ^2)+2*MVZ*covb3b4 + varb5+2*covb3b5);

gen bound2 = 1.96*se_formateur;

gen upper2 = marginal_formateur+bound2;

gen lower2 = marginal_formateur-bound2;

*     ****************************************************************  *;
*       Produce Figure 5 (appendix), Panel b: Formateur parties         *;
*     ****************************************************************  *;

graph twoway hist seatshare if formateur==1 & seatshare<0.99 & seatshare>0.04, width(0.04) percent color(gs15) yaxis(2)
    || line marginal_formateur MVZ if MVZ<0.99 & MVZ>0.042, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower2 MVZ if MVZ<0.99 & MVZ>0.042, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper2 MVZ if MVZ<0.99 & MVZ>0.042, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel(0 0.05 0.10 0.15 0.20 0.25, axis(1) nogrid labsize(2.5))
    ylabel(0 3 6 9 12, axis(2) nogrid labsize(2) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(b) Formateur Parties}",  size(3.5))
        xtitle("{stSerif:Share of Government's Legislative Seats}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Africa}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white));
        
    
graph export "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\formateur.eps", replace;



log close;
exit;

